package com.company.huisuo.repository

import com.company.huisuo.biz.bean.RoomStyle
import com.company.huisuo.biz.bean.RoomStyleResponse
import com.company.huisuo.network.RetrofitClient
import com.company.huisuo.network.api.RoomStyleApi
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext

/**
 * 房间风格数据仓库
 */
class RoomStyleRepository {
    
    private val roomStyleApi: RoomStyleApi by lazy {
        RetrofitClient.createService()
    }
    
    /**
     * 获取房间风格列表
     */
    suspend fun getRoomStyleList(): Result<List<RoomStyle>> = withContext(Dispatchers.IO) {
        try {
            val response = roomStyleApi.getRoomStyleList()
            if (response.code == 0 && response.data != null) {
                Result.success(response.data)
            } else {
                Result.failure(Exception(response.msg ?: "获取房间风格列表失败"))
            }
        } catch (e: Exception) {
            Result.failure(Exception("网络请求失败: ${e.message}"))
        }
    }
}